home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / croutes.zip / CVTDATE.C < prev    next >
Text File  |  1984-04-05  |  2KB  |  87 lines

  1. /*                     *** cvtdate.c ***                             */
  2. /*                                                                   */
  3. /* IBM - PC microsoft "C"                                            */
  4. /*                                                                   */
  5. /* Function to check and convert a "packed" gregorian date (1/1/83)  */
  6. /* into its "expanded" form (01/01/83).  Will return a 0 if success- */
  7. /* ful or a -1 if unable to convert gregorian date received.         */
  8. /*                                                                   */
  9. /* WARNING - if indate has not been declared at least 9 characters a */
  10. /*           memory overwrite will occure.                           */
  11. /*                                                                   */
  12. /* Written by L. Cuthbertson, March 1984.                            */
  13. /*                                                                   */
  14. /*********************************************************************/
  15. /*                                                                   */
  16.  
  17. #include <ctype.h>
  18.  
  19. int cvtdate(indate)
  20. char indate[];
  21. {
  22.     char hold[9];
  23.     int i;
  24.  
  25.     i = 0;        /* position within indate */
  26.  
  27.     /* get month */
  28.     if (isdigit(indate[i]))
  29.         if (isdigit(indate[i+1])) {
  30.             hold[0] = indate[i++];
  31.             hold[1] = indate[i++];
  32.         } else {
  33.             hold[0] = '0';
  34.             hold[1] = indate[i++];
  35.         }
  36.     else
  37.         return(-1);
  38.  
  39.     /* insert slash */
  40.     if (isdigit(indate[i++]))
  41.         return(-1);
  42.     else
  43.         hold[2] = '/';
  44.  
  45.     /* get day */
  46.     if (isdigit(indate[i]))
  47.         if (isdigit(indate[i+1])) {
  48.             hold[3] = indate[i++];
  49.             hold[4] = indate[i++];
  50.         } else {
  51.             hold[3] = '0';
  52.             hold[4] = indate[i++];
  53.         }
  54.     else
  55.         return(-1);
  56.  
  57.     /* insert slash */
  58.     if (isdigit(indate[i++]))
  59.         return(-1);
  60.     else
  61.         hold[5] = '/';
  62.  
  63.     /* get year */
  64.     if (isdigit(indate[i]))
  65.         if (isdigit(indate[i+1])) {
  66.             hold[6] = indate[i++];
  67.             hold[7] = indate[i++];
  68.         } else {
  69.             hold[6] = '0';
  70.             hold[7] = indate[i++];
  71.         }
  72.     else
  73.         return(-1);
  74.  
  75.     /* insert null terminator */
  76.     if (indate[i] != '\0')
  77.         return(-1);
  78.     else
  79.         hold[8] = '\0';
  80.  
  81.     /* copy hold into indate */
  82.     strcpy(indate,hold);
  83.  
  84.     /* done */
  85.     return(0);
  86. }
  87.